/*
ID: guoxu1
PROG: runround
LANG: C++
*/
#include <fstream>
#include <cstring>
using namespace std;

bool isRunaround( int n )
{
	char str[10] = {0};
	bool flags[10] = {false};
	bool unique[10] = {true};
	sprintf( str, "%d", n );
	int len = strlen(str);

	int p = 0;
	for( int i = 0; i < len; i++ )
	{
		while( p > len ) p -= len;
		int v = str[p] - '0';
		if( unique[v] ) return false;
		if( flags[i] ) return false;
		unique[v] = true;
		flags[i] = true;
		p += v;
	}
	return (p % len == 0);
}

#define cin fin
#define cout fout

int main()
{
	ifstream fin( "runround.in" );
	ofstream fout( "runround.out" );

	int n = 0;
	cin >> n;
	while(true)
	{
		if( isRunaround( ++n ) )
		{
			cout << n << endl;
			return 0;
		}
	}
	return 0;
}